package com.sdry.service.impl.hpf;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.hpf.BomMapper;
import com.sdry.mapper.hpf.CacheAreaMapper;
import com.sdry.mapper.hpf.CacheAreaOutMapper;
import com.sdry.mapper.hpf.LineSideLibraryInMapper;
import com.sdry.mapper.hpf.LineSideLibraryMapper;
import com.sdry.mapper.hpf.LineSideLibraryOutMapper;
import com.sdry.mapper.hpf.PartMapper;
import com.sdry.mapper.hpf.PickApplyDetailMapper;
import com.sdry.mapper.hpf.PickApplyMapper;
import com.sdry.mapper.hpf.ProductMapper;
import com.sdry.model.hpf.Bom;
import com.sdry.model.hpf.CacheArea;
import com.sdry.model.hpf.CacheAreaOut;
import com.sdry.model.hpf.FinishProductLibrary;
import com.sdry.model.hpf.FinishProductLibraryIn;
import com.sdry.model.hpf.LineSideLibrary;
import com.sdry.model.hpf.LineSideLibraryIn;
import com.sdry.model.hpf.LineSideLibraryOut;
import com.sdry.model.hpf.Part;
import com.sdry.model.hpf.PickApply;
import com.sdry.model.hpf.PickApplyDetail;
import com.sdry.model.hpf.Product;
import com.sdry.model.llm.Department;
import com.sdry.model.llm.User;
import com.sdry.service.hpf.FinishProductLibraryInService;
import com.sdry.service.hpf.FinishProductLibraryService;
import com.sdry.service.hpf.LineSideLibraryService;
import com.sdry.utils.PushExample;
import com.sdry.utils.SerialComm4MainWindows;
import com.sdry.utils.StringUtil;

/**
 * @ClassName: LineSideLibraryServiceimpl 
 * @Description:线边库Service实现
 * @Author hpf
 * @Date 2018年9月19日 上午11:34:33 
 * @version 1.0
 */
@Service("lineSideLibraryService")
public class LineSideLibraryServiceimpl implements LineSideLibraryService {

	@Resource
	private LineSideLibraryMapper lineSideLibraryMapper;
	@Resource
	private CacheAreaMapper cacheAreaMapper;
	@Resource
	private PartMapper partMapper;
	@Resource
	private ProductMapper productMapper;
	@Resource
	private BomMapper bomMapper;
	@Resource
	private PickApplyMapper pickApplyMapper;
	@Resource
	private PickApplyDetailMapper pickApplyDetailMapper;
	@Resource
	private LineSideLibraryOutMapper lineSideLibraryOutMapper;
	@Resource
	private CacheAreaOutMapper cacheAreaOutMapper;
	@Resource
	private LineSideLibraryInMapper lineSideLibraryInMapper;
	@Resource
	private FinishProductLibraryService finishProductLibraryService;
	@Resource
	private FinishProductLibraryInService finishProductLibraryInService;
	
	/**
	 * 线边库总数
	 * @param lineSideLibrary
	 * @return
	 */
	public Integer countLineSideLibrary(LineSideLibrary lineSideLibrary) {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.countLineSideLibrary(lineSideLibrary);
	}

	/**
	 * 分页查询线边库
	 * @param map
	 * @return
	 */
	public List<LineSideLibrary> listPageLineSideLibrary(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.listPageLineSideLibrary(map);
	}

	/**
	 * 查询所有线边库
	 * @return
	 */
	public List<LineSideLibrary> listAllLineSideLibrary() {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.listAllLineSideLibrary();
	}

	/**
	 * 叫料批量新增线边库
	 * @param paID 配件ID
	 * @param batch 批次号
	 * @param quantity 数量
	 * @param session
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer insertLineSideLibrary(Long[] paID,String[] batch,String[] quantity,HttpSession session) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			int num = 0;
			int type = 0;
			for (int i = 0; i < paID.length; i++) {
				Part part = partMapper.findPartByPaid(paID[i]);
				CacheArea cacheArea = cacheAreaMapper.findCacheAreaByPaID(paID[i]);
				if (null == cacheArea) {
					//给ERP发送叫料
					PickApply pickApply = new PickApply();
					User user = (User) session.getAttribute("currentUser");
					Department department = (Department) session.getAttribute("department");
					pickApply.setPickDept(department.getDid());
					pickApply.setPickPerson(user.getUid());
					pickApply.setReserve1("0");
					pickApply.setReserve4("1");
					pickApply.setPickNum("P"+getRandomNumber(12));
					pickApply.setPickDate(new Date());
					pickApply.setDemandDate(new Date());
					int pickID = pickApplyMapper.insertPickApply(pickApply);
					isSuccess = pickID;
					PickApplyDetail pickApplyDetail = new PickApplyDetail();
					pickApplyDetail.setPickID(Long.parseLong(pickID+""));
					pickApplyDetail.setStockNum(part.getPanum());
					pickApplyDetail.setStockName(part.getPaname());
					pickApplyDetail.setStockModel(part.getPamodel());
					pickApplyDetail.setReserve1(part.getParemark1());
					pickApplyDetail.setReserve2(part.getParemark2());
					pickApplyDetail.setReserve3(batch[i]);
					pickApplyDetail.setQuantity(StringUtil.calcFloatValue(quantity[i], "0", "add"));
					isSuccess = pickApplyDetailMapper.insertPickApplyDetail(pickApplyDetail);
					type = 1;
				} else if (Float.parseFloat(StringUtil.calcFloatValue(cacheArea.getQuantity(), quantity[i], "subtract"))  < 0) {
					//给ERP发送叫料
					PickApply pickApply = new PickApply();
					User user = (User) session.getAttribute("currentUser");
					Department department = (Department) session.getAttribute("department");
					pickApply.setPickDept(department.getDid());
					pickApply.setPickPerson(user.getUid());
					pickApply.setReserve1("0");
					pickApply.setReserve4("1");
					pickApply.setPickNum("P"+getRandomNumber(12));
					pickApply.setPickDate(new Date());
					pickApply.setDemandDate(new Date());
					int pickID = pickApplyMapper.insertPickApply(pickApply);
					isSuccess = pickID;
					PickApplyDetail pickApplyDetail = new PickApplyDetail();
					pickApplyDetail.setPickID(Long.parseLong(pickID+""));
					pickApplyDetail.setStockNum(part.getPanum());
					pickApplyDetail.setStockName(part.getPaname());
					pickApplyDetail.setStockModel(part.getPamodel());
					pickApplyDetail.setReserve1(part.getParemark1());
					pickApplyDetail.setReserve2(part.getParemark2());
					pickApplyDetail.setReserve3(batch[i]);
					pickApplyDetail.setQuantity(StringUtil.calcFloatValue(cacheArea.getQuantity(), quantity[i], "subtract"));
					isSuccess = pickApplyDetailMapper.insertPickApplyDetail(pickApplyDetail);
					type = 1;
				} else {
					//给AGV小车命令拉料
					SerialComm4MainWindows.sendMsg("COM3", "线边库缺料:", part.getPanum(), part.getPaname(), part.getPamodel(), part.getParemark1(), part.getParemark2(), batch[i], quantity[i], "1", "手动叫料");
					num = 1;
				}
			}
			if (num == 1) {
				(new SerialComm4MainWindows()).connect("COM3");
			}
			if (type == 1) {
				if (num == 0) {
					isSuccess = 2;
				} else {
					isSuccess = 3;
				}
			} else {
				isSuccess = 1;
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}
	
	/**
	 * 新增线边库
	 * @param paID 配件ID
	 * @param batch 批次号
	 * @param quantity 数量
	 * @param productionOrder 排产单号（0:线边库叫料）
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer insert(Long paID,String batch,String quantity,String productionOrder) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			CacheArea cacheArea = cacheAreaMapper.findCacheAreaByPaID(paID);
			String lessQuantity = StringUtil.calcFloatValue(cacheArea.getQuantity(), quantity, "subtract");
			cacheArea.setQuantity(lessQuantity);
			isSuccess = cacheAreaMapper.updateCacheArea(cacheArea);
			LineSideLibrary lineSideLibrary = lineSideLibraryMapper.findLineSideLibraryByPaID(paID);
			if (lineSideLibrary != null) {
				if (lineSideLibrary.getBatch().equals(batch)) {
					String addQuantity = StringUtil.calcFloatValue(lineSideLibrary.getQuantity(), quantity, "add");
					lineSideLibrary.setQuantity(addQuantity);
					isSuccess = lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
				} else {
					LineSideLibrary lineSideLibrary2 = new LineSideLibrary();
					lineSideLibrary2.setPaID(paID);
					lineSideLibrary2.setBatch(batch);
					lineSideLibrary2.setQuantity(quantity);
					isSuccess = lineSideLibraryMapper.insertLineSideLibrary(lineSideLibrary2);
				}
			} else {
				LineSideLibrary lineSideLibrary2 = new LineSideLibrary();
				lineSideLibrary2.setPaID(paID);
				lineSideLibrary2.setBatch(batch);
				lineSideLibrary2.setQuantity(quantity);
				isSuccess = lineSideLibraryMapper.insertLineSideLibrary(lineSideLibrary2);
			}
			CacheAreaOut cacheAreaOut = new CacheAreaOut();
			cacheAreaOut.setPaID(paID);
			cacheAreaOut.setOutQuantity(quantity);
			cacheAreaOut.setOutDate(new Date());
			cacheAreaOut.setBatch(batch);
			if ("0".equals(productionOrder)) {
				cacheAreaOut.setReserve1("1");
				cacheAreaOut.setReserve2("");
			} else {
				cacheAreaOut.setReserve1("0");
				cacheAreaOut.setReserve2(productionOrder);
			}
			isSuccess = cacheAreaOutMapper.insertCacheAreaOut(cacheAreaOut);
			LineSideLibraryIn lineSideLibraryIn = new LineSideLibraryIn();
			lineSideLibraryIn.setPaID(paID);
			lineSideLibraryIn.setInQuantity(quantity);
			lineSideLibraryIn.setInDate(new Date());
			lineSideLibraryIn.setBatch(batch);
			if ("0".equals(productionOrder)) {
				lineSideLibraryIn.setReserve1("1");
				lineSideLibraryIn.setProductionOrder("");
			} else {
				lineSideLibraryIn.setReserve1("0");
				lineSideLibraryIn.setProductionOrder(productionOrder);
			}
			isSuccess = lineSideLibraryInMapper.insertLineSideLibraryIn(lineSideLibraryIn);
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

	/**
	 * 跟新线边库
	 * @param lineSideLibrary 线边库实体
	 * @return
	 */
	public Integer updateLineSideLibrary(LineSideLibrary lineSideLibrary) {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
	}

	/**
	 * 根据配件ID查询线边库
	 * @param paID 配件ID
	 * @return
	 */
	public LineSideLibrary findLineSideLibraryByPaID(Long paID) {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.findLineSideLibraryByPaID(paID);
	}

	/**
	 * 设置预警值
	 * @param lineSideLibrary 线边库实体
	 * @return
	 */
	public Integer setWarningValue(LineSideLibrary lineSideLibrary) {
		// TODO Auto-generated method stub
		return lineSideLibraryMapper.setWarningValue(lineSideLibrary);
	}

	/**
	 * 线边库出库
	 * @param pnum 产品编码
	 * @param quantity 数量
	 * @param productionOrder 排产单号
	 * @param team 班组名称
	 * @param type 1合格2报废3让步接收4降级
	 */
	@Transactional(rollbackFor={Exception.class})
	public void lineSideLibraryOut(String pnum, String quantity, String productionOrder, String team, String type, HttpSession session) {
		// TODO Auto-generated method stub
		try {
			long datetime = new Date().getTime();
			Product product = productMapper.findProductByPnum(pnum);
			List<Bom> bomList = bomMapper.listAllBom(product.getPid());
			for (int i = 0; i < bomList.size(); i++) {
				LineSideLibrary lineSideLibrary = lineSideLibraryMapper.findLineSideLibraryByPaID(bomList.get(i).getPaid());
				Date d = new Date();
				SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
				String lQuantity = "0";
				String lowerLimit = "0";
				if (lineSideLibrary.getReserve1() != null && !"".equals(lineSideLibrary.getReserve1())) {
					lQuantity = lineSideLibrary.getReserve1();
				} else {
					lQuantity = lineSideLibrary.getQuantity();
				}
				if (lineSideLibrary.getLowerLimit() != null) {
					lowerLimit = lineSideLibrary.getLowerLimit();
				}
				if (Float.parseFloat(StringUtil.calcFloatValue(lQuantity, (StringUtil.calcFloatValue(quantity, bomList.get(i).getNumber(), "multiply")), "subtract"))  < Float.parseFloat(lowerLimit)) {
					User u = lineSideLibraryMapper.findCurrentTeam(f.format(d));
					PushExample.testSendPush("库存消息", "线边库库存低于预警值", u.getUserName(), "1");
				}
				lineSideLibrary.setQuantity(StringUtil.calcFloatValue(lQuantity, (StringUtil.calcFloatValue(quantity, bomList.get(i).getNumber(), "multiply")), "subtract"));
				LineSideLibraryOut lineSideLibraryOut = new LineSideLibraryOut();
				lineSideLibraryOut.setProductionOrder(productionOrder);
				User user = (User)session.getAttribute("currentUser");
				String today = user.getRemark3();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				Date date = sdf.parse(today);
				lineSideLibraryOut.setOutDate(date);
				lineSideLibraryOut.setPaID(lineSideLibrary.getPaID());
				lineSideLibraryOut.setOutQuantity(StringUtil.calcFloatValue((StringUtil.calcFloatValue(quantity, "0.0", "add")), bomList.get(i).getNumber(), "multiply"));
				lineSideLibraryOut.setBatch(lineSideLibrary.getBatch());
				lineSideLibraryOut.setReserve1(team);
				lineSideLibraryOut.setReserve2(pnum);
				lineSideLibraryOut.setReserve3(type);
				lineSideLibraryOut.setReserve4(datetime+"");
				lineSideLibraryOutMapper.insertLineSideLibraryOut(lineSideLibraryOut);
				String residue = lineSideLibrary.getQuantity();
//				if("0".equals(residue) || "0.00".equals(residue)){
//					lineSideLibraryMapper.deleteLineSideLibrary(lineSideLibrary.getLslID());
//				}else{
//					lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
//				}
				if("0.00".equals(residue)){
					lineSideLibrary.setQuantity("0");
					lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
				}
				int quan = Integer.parseInt(quantity);
				if (!"2".equals(type)) {
					FinishProductLibrary fLibrary = finishProductLibraryService.findFinishProductLibraryByPid(product.getPid());
					if (fLibrary != null) {
						int q = fLibrary.getQuantity() + quan;
						fLibrary.setQuantity(q);
						finishProductLibraryService.updateFinishProductLibrary(fLibrary);
					} else {
						FinishProductLibrary finishProductLibrary = new FinishProductLibrary();
						finishProductLibrary.setPid(product.getPid());
						finishProductLibrary.setQuantity(quan);
					}
					FinishProductLibraryIn finishProductLibraryIn = new FinishProductLibraryIn();
					finishProductLibraryIn.setPid(product.getPid());
					finishProductLibraryIn.setInDate(new Date());
					finishProductLibraryIn.setInQuantity(quan);
					finishProductLibraryInService.insertFinishProductLibraryIn(finishProductLibraryIn);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
	}
	
	/**
	 * 线边库出库
	 * @param pnum 产品编码
	 * @param quantity 数量
	 * @param productionOrder 排产单号
	 * @param team 班组名称
	 * @param type 1合格2报废3让步接收4降级
	 * @param positionName	工位名称
	 */
	@Transactional(rollbackFor={Exception.class})
	public void newLineSideLibraryOut(String pnum, String quantity, String productionOrder, String team, String type, HttpSession session, String positionName) {
		try {
			long datetime = new Date().getTime();
			Product product = productMapper.findProductByPnum(pnum);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("productId", product.getPid());
			map.put("positionName", positionName);
			List<Bom> bomList = bomMapper.getBomByPaidAndPositionName(map);
			
			for (int i = 0; i < bomList.size(); i++) {
				LineSideLibrary lineSideLibrary = lineSideLibraryMapper.findLineSideLibraryByPaID(bomList.get(i).getPaid());
				Date d = new Date();
				SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
				String lQuantity = "0";
				String lowerLimit = "0";
				if(lineSideLibrary != null){
					if (lineSideLibrary.getReserve1() != null && !"".equals(lineSideLibrary.getReserve1())) {
						lQuantity = lineSideLibrary.getReserve1();
					} else {
						lQuantity = lineSideLibrary.getQuantity();
					}
					if (lineSideLibrary.getLowerLimit() != null) {
						lowerLimit = lineSideLibrary.getLowerLimit();
					}
					String bomNumber1 = StringUtil.calcFloatValue(quantity, bomList.get(i).getNumber(), "multiply");
					String lastNumber = StringUtil.calcFloatValue(lQuantity, bomNumber1, "subtract");
					if (Float.parseFloat(lastNumber)  < Float.parseFloat(lowerLimit)) {
						User u = lineSideLibraryMapper.findCurrentTeam(f.format(d));
						PushExample.testSendPush("库存消息", "线边库库存低于预警值", u.getUserName(), "1");
					}
					String bomNumber2 = StringUtil.calcFloatValue(quantity, bomList.get(i).getNumber(), "multiply");
					String lastNumber2 = StringUtil.calcFloatValue(lQuantity, bomNumber2, "subtract");
					lineSideLibrary.setQuantity(lastNumber2);
					LineSideLibraryOut lineSideLibraryOut = new LineSideLibraryOut();
					lineSideLibraryOut.setProductionOrder(productionOrder);
					User user = (User)session.getAttribute("currentUser");
					String today = user.getRemark3();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					Date date = sdf.parse(today);
					lineSideLibraryOut.setOutDate(date);
					lineSideLibraryOut.setPaID(lineSideLibrary.getPaID());
					String bomNumber3 = StringUtil.calcFloatValue(quantity, "0", "add");
					String lastNumber3 = StringUtil.calcFloatValue(bomNumber3, bomList.get(i).getNumber(), "multiply");
					lineSideLibraryOut.setOutQuantity(lastNumber3);
					lineSideLibraryOut.setBatch(lineSideLibrary.getBatch());
					lineSideLibraryOut.setReserve1(team);
					lineSideLibraryOut.setReserve2(pnum);
					lineSideLibraryOut.setReserve3(type);
					lineSideLibraryOut.setReserve4(datetime+"");
					lineSideLibraryOut.setReserve5(positionName);
					lineSideLibraryOutMapper.insertLineSideLibraryOut(lineSideLibraryOut);
					lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
	}

	/**
	 * 线边库盘点
	 * @param lineSideLibraryList
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer lineSideLibraryCheck(List<LineSideLibrary> lineSideLibraryList) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			for (int i = 0; i < lineSideLibraryList.size(); i++) {
				isSuccess = lineSideLibraryMapper.lineSideLibraryCheck(lineSideLibraryList.get(i));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}
	
	/**
	 * 生成随机数
	 * @param digCount 随机数位数
	 * @return
	 */
	public static String getRandomNumber(int digCount) {
		Random rnd = new Random();
	    StringBuilder sb = new StringBuilder(digCount);
	    for(int i=0; i < digCount; i++)
	        sb.append((char)('0' + rnd.nextInt(10)));
	    return sb.toString();
	}

	@Transactional(rollbackFor={Exception.class})
	public Integer lineSideLibraryEmpty(List<LineSideLibrary> lineSideLibraryList) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			for (int i = 0; i < lineSideLibraryList.size(); i++) {
				isSuccess = lineSideLibraryMapper.lineSideLibraryEmpty(lineSideLibraryList.get(i));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

	/**       
	 * @param paID 配件
	 * @param batch 批次号
	 * @param quantity 数量
	 * @param productionOrder 排产单号
	 */
	@Override
	public Integer twoInsert(Long paID, String batch, String quantity, String productionOrder) {
		int isSuccess = 0;
		try {
			LineSideLibrary lineSideLibrary = lineSideLibraryMapper.findLineSideLibraryByPaID(paID);
			if (lineSideLibrary != null) {
				if (lineSideLibrary.getBatch().equals(batch)) {
					String addQuantity = StringUtil.calcFloatValue(lineSideLibrary.getQuantity(), quantity, "add");
					lineSideLibrary.setQuantity(addQuantity);
					isSuccess = lineSideLibraryMapper.updateLineSideLibrary(lineSideLibrary);
				} else {
					LineSideLibrary lineSideLibrary2 = new LineSideLibrary();
					lineSideLibrary2.setPaID(paID);
					lineSideLibrary2.setBatch(batch);
					lineSideLibrary2.setQuantity(quantity);
					isSuccess = lineSideLibraryMapper.insertLineSideLibrary(lineSideLibrary2);
				}
			} else {
				LineSideLibrary lineSideLibrary2 = new LineSideLibrary();
				lineSideLibrary2.setPaID(paID);
				lineSideLibrary2.setBatch(batch);
				lineSideLibrary2.setQuantity(quantity);
				isSuccess = lineSideLibraryMapper.insertLineSideLibrary(lineSideLibrary2);
			}
			LineSideLibraryIn lineSideLibraryIn = new LineSideLibraryIn();
			lineSideLibraryIn.setPaID(paID);
			lineSideLibraryIn.setInQuantity(quantity);
			lineSideLibraryIn.setInDate(new Date());
			lineSideLibraryIn.setBatch(batch);
			if ("0".equals(productionOrder)) {
				lineSideLibraryIn.setReserve1("1");
				lineSideLibraryIn.setProductionOrder("");
			} else {
				lineSideLibraryIn.setReserve1("0");
				lineSideLibraryIn.setProductionOrder(productionOrder);
			}
			isSuccess = lineSideLibraryInMapper.insertLineSideLibraryIn(lineSideLibraryIn);
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

	/**       
	 * @param paid
	 * @return    
	 */
	@Override
	public LineSideLibraryOut findLineSideLibraryOutByPaID(Long paid) {
		return lineSideLibraryMapper.findLineSideLibraryOutByPaID(paid);
	}

}
